package com.stream.service.impl;

import com.google.common.collect.Maps;
import com.stream.repository.SysUserRoleRepository;
import com.stream.service.SySUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by yebaokang on 2017/5/23.
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements SySUserRoleService {

    @SuppressWarnings("all")
    @Autowired
    private SysUserRoleRepository sysUserRoleRepository;

    @Override
    public void saveOrUpdate(Long userId, List<Long> roleIdList) {
        if (roleIdList.size() == 0) {
            return;
        }

        //先删除用户与角色关系
        sysUserRoleRepository.delete(userId);

        //保存用户与角色关系
        Map<String,Object> map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("roleIdList", roleIdList);
        sysUserRoleRepository.save(map);
    }

    @Override
    public List<Long> queryRoleIdList(Long userId) {
        return sysUserRoleRepository.queryRoleIdList(userId);
    }

    @Override
    public void delete(Long userId) {
        sysUserRoleRepository.delete(userId);
    }
}
